package com.itcast.demo_one.kotlin

fun main() {
//    println(ifFunc(100, 200))
    println(getGrade1(80))
    println(getGrade2(40))
    println(getGrade3(90))
}

// 1. if语句
fun ifFunc(num1: Int, num2: Int): Int {
    // 写法1:
    return if(num1 > num2){
        num1
    } else {
        num2
    }

    // 写法2:简写
//    return if (num1 > num2) num1 else num2
}

// 2. when语句
fun getGrade1(score: Int): String {
    return when{
        score >= 90 -> "优秀"
        score >= 80 -> "良好"
        score >= 70 -> "一般"
        score >=60 -> "及格"
        else -> "输入的分数有误"
    }
}

// 3. when语句 用in
fun getGrade2(score: Int): String {
    return when (score) {
        in 0..60 -> "不及格"
        in 60..80 -> "及格"
        in 80..100 -> "优秀"
        else -> "输入的分数有误"
    }
}

// 4. when语句 用in 和until
fun getGrade3(score: Int): String {
    return when(score){
        in 90 until 101 -> "优秀"
        in 80 until 90 -> "良好"
        in 60 until 80 -> "及格"
        in 0 until 60 -> "不及格"
        else -> "输入的分数有误"
    }
}

